package com.kai.controller;

import com.kai.pojo.City;
import com.kai.pojo.County;
import com.kai.pojo.Province;
import com.kai.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class AddressController {
    @Autowired
    private AddressService addressService;

    /**
     * 查询省
     * @return
     */
    @RequestMapping("/selectAllProvince")
    public List<Province> selectAllProvince(){
        return addressService.selectAllProvince();
    }
    @RequestMapping("/selectCityByValue")
    public List<City> selectCityByValue(String cvalue){
        return addressService.selectCityByValue(cvalue);
    }
    @RequestMapping("/selectCountyByValue")
    public List<County> selectCountyByValue(String cvalue){
        return addressService.selectCountyByValue(cvalue);
    }

    @RequestMapping("selectProvinceCityCounty")
    public Map selectProvinceCityCounty(String pv,String civ){
        Map<String, Object> map = new HashMap<>();
        List<Province> provinces = addressService.selectAllProvince();
        List<City> cities = addressService.selectCityByValue(pv);
        List<County> counties = addressService.selectCountyByValue(civ);
        map.put("provinces",provinces);
        map.put("cities",cities);
        map.put("counties",counties);
        return map;
    }

}
